package com.senthink.gl.business.fault;

import com.senthink.gl.business.common.exception.BusinessException;
import com.senthink.gl.business.messages.CodeMsg;
import lombok.Getter;

/**
 * 故障等级枚举定义
 *
 * @author zooqi@senthink.com
 * @date 2017/12/04
 */
@Getter
public enum FaultLevelEnum {

    NOTIFY(1, "一般"),

    MEDIUM(2, "紧急"),

    SERIOUS(3, "非常紧急");

    private int level;

    private String description;

    FaultLevelEnum(int level, String description) {
        this.level = level;
        this.description = description;
    }

    public static FaultLevelEnum fromLevel(Integer level, CodeMsg codeMsg) {
        if (level == null) {
            throw new BusinessException(codeMsg.illegalArgumentCode(), codeMsg.illegalArgumentMsg());
        }
        switch (level) {
            case 1:
                return NOTIFY;
            case 2:
                return MEDIUM;
            case 3:
                return SERIOUS;
            default:
                throw new BusinessException(codeMsg.illegalArgumentCode(), codeMsg.illegalArgumentMsg());
        }
    }

    public static FaultLevelEnum fromLevel(Integer level) {
        if (level == null) {
            throw new IllegalArgumentException();
        }
        switch (level) {
            case 1:
                return NOTIFY;
            case 2:
                return MEDIUM;
            case 3:
                return SERIOUS;
            default:
                throw new IllegalArgumentException("No such fault level");
        }
    }
}
